#include <iostream>
#include <cstring>
#include <fcntl.h>
#include <unistd.h>
using namespace std;

class File
{
public:
    File(const char* name)
    {
        this->fp = open(name,O_WRONLY);
        if(this->fp == -1)
        {
            cout << "文件打开失败" << endl;
        }
    }
    int write(const char* buf)
    {
        return ::write(this->fp, buf, strlen(buf));
    }
private:
    int fp;
};

int main()
{
    File f1("test.txt");
    int ret = f1.write("hello world");
    if(ret == -1)
    {
        cout << "文件写入失败" << endl;
    }
    return 0;
}